<?php if (!defined('THINK_PATH')) exit(); /*a:4:{s:86:"G:\phpstudy\PHPTutorial\WWW\zudian\public/../application/admin\view\commodity\add.html";i:1559026039;s:77:"G:\phpstudy\PHPTutorial\WWW\zudian\application\admin\view\layout\default.html";i:1557482264;s:74:"G:\phpstudy\PHPTutorial\WWW\zudian\application\admin\view\common\meta.html";i:1557482264;s:76:"G:\phpstudy\PHPTutorial\WWW\zudian\application\admin\view\common\script.html";i:1557482264;}*/ ?>
<!DOCTYPE html>
<html lang="<?php echo $config['language']; ?>">
    <head>
        <meta charset="utf-8">
<title><?php echo (isset($title) && ($title !== '')?$title:''); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">

<link rel="shortcut icon" href="/assets/img/favicon.ico" />
<!-- Loading Bootstrap -->
<link href="/assets/css/backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.css?v=<?php echo \think\Config::get('site.version'); ?>" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
<!--[if lt IE 9]>
  <script src="/assets/js/html5shiv.js"></script>
  <script src="/assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
    var require = {
        config:  <?php echo json_encode($config); ?>
    };
</script>
    </head>

    <body class="inside-header inside-aside <?php echo defined('IS_DIALOG') && IS_DIALOG ? 'is-dialog' : ''; ?>">
        <div id="main" role="main">
            <div class="tab-content tab-addtabs">
                <div id="content">
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <section class="content-header hide">
                                <h1>
                                    <?php echo __('Dashboard'); ?>
                                    <small><?php echo __('Control panel'); ?></small>
                                </h1>
                            </section>
                            <?php if(!IS_DIALOG && !$config['fastadmin']['multiplenav']): ?>
                            <!-- RIBBON -->
                            <div id="ribbon">
                                <ol class="breadcrumb pull-left">
                                    <li><a href="dashboard" class="addtabsit"><i class="fa fa-dashboard"></i> <?php echo __('Dashboard'); ?></a></li>
                                </ol>
                                <ol class="breadcrumb pull-right">
                                    <?php foreach($breadcrumb as $vo): ?>
                                    <li><a href="javascript:;" data-url="<?php echo $vo['url']; ?>"><?php echo $vo['title']; ?></a></li>
                                    <?php endforeach; ?>
                                </ol>
                            </div>
                            <!-- END RIBBON -->
                            <?php endif; ?>
                            <div class="content">
                                <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Name'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Sort_id'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-sort_id" data-rule="required" data-source="sort/index" class="form-control selectpage" name="row[sort_id]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Image'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> <?php echo __('Upload'); ?></button></span>
                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> <?php echo __('Choose'); ?></button></span>
                </div>
                <span class="msg-box n-right" for="c-image"></span>
            </div>
            <ul class="row list-inline plupload-preview" id="p-image"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Images'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-images" data-rule="required" class="form-control" size="50" name="row[images]" type="text">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="plupload-images" class="btn btn-danger plupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> <?php echo __('Upload'); ?></button></span>
                    <span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> <?php echo __('Choose'); ?></button></span>
                </div>
                <span class="msg-box n-right" for="c-images"></span>
            </div>
            <ul class="row list-inline plupload-preview" id="p-images"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Price'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-price" data-rule="required" class="form-control" step="0.01" name="row[price]" type="number">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('S_price'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-s_price" data-rule="required" class="form-control" step="0.01" name="row[s_price]" type="number">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Sum'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-sum" data-rule="required" class="form-control" name="row[sum]" type="number">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Num'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-num" data-rule="required" class="form-control" name="row[num]" type="number">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Type'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
                <?php if(is_array($typeList) || $typeList instanceof \think\Collection || $typeList instanceof \think\Paginator): if( count($typeList)==0 ) : echo "" ;else: foreach($typeList as $key=>$vo): ?>
                    <option value="<?php echo $key; ?>" <?php if(in_array(($key), explode(',',"1"))): ?>selected<?php endif; ?>><?php echo $vo; ?></option>
                <?php endforeach; endif; else: echo "" ;endif; ?>
            </select>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Norm'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="control-group">
                <label class="control-label"> </label>
                <div class="controls">
                    <button id="add_lv1" class="btn btn-primary" type="button">添加规格项</button>
                    <button id="update_table" class="btn btn-success" type="button">新增规格项目表</button>
                </div>
            </div>
            <div id="lv_table_con" class="control-group" style="display: none;">
                <label class="control-label">规格项目表</label>
                <div class="controls">
                    <div id="lv_table">

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        var lv1HTML = '<div class="control-group lv1">' +
            '<label class="control-label">规格名称</label>' +
            '<div class="controls">' +
            '<input type="text" name="lv1" placeholder="规格名称">' +
            '<button class="btn btn-primary add_lv2" type="button">添加参数</button>' +
            '<button class="btn btn-danger remove_lv1" type="button">删除规格</button>' +
            '</div>' +
            '<div class="controls lv2s"></div>' +
            '</div>';

        var lv2HTML = '<div style="margin-top: 5px;">' +
            '<input type="text" name="lv2[]" placeholder="参数名称">' +
            '<button class="btn btn-danger remove_lv2" type="button">删除参数</button>' +
            '</div>';

        $(document).ready(function() {
            $('#add_lv1').on('click', function() {
                var last = $('.control-group.lv1:last');
                if (!last || last.length == 0) {
                    $(this).parents('.control-group').eq(0).after(lv1HTML);
                } else {
                    last.after(lv1HTML);
                }
            });

            $(document).on('click', '.remove_lv1', function() {
                $(this).parents('.lv1').remove();
            });

            $(document).on('click', '.add_lv2', function() {
                $(this).parents('.lv1').find('.lv2s').append(lv2HTML);
            });

            $(document).on('click', '.remove_lv2', function() {
                $(this).parent().remove();
            });

            $('#update_table').on('click', function() {
                var lv1Arr = $('input[name="lv1"]');
                if (!lv1Arr || lv1Arr.length == 0) {
                    $('#lv_table_con').hide();
                    $('#lv_table').html('');
                    return;
                }
                for (var i = 0; i < lv1Arr.length; i++) {
                    var lv2Arr = $(lv1Arr[i]).parents('.lv1').find('input[name="lv2[]"]');
                    if (!lv2Arr || lv2Arr.length == 0) {
                        alert('请先删除无参数的规格项！');
                        return;
                    }
                }

                var tableHTML = '';
                tableHTML += '<table class="table table-bordered">';
                tableHTML += '    <thead>';
                tableHTML += '        <tr>';
                for (var i = 0; i < lv1Arr.length; i++) {
                    tableHTML += '<th width="50">' + $(lv1Arr[i]).val() + '</th>';
                }
                tableHTML += '            <th width="20">尺码（多个尺码用空格隔开）</th>';
                tableHTML += '            <th width="20">库存</th>';
                tableHTML += '            <th width="20">操作</th>';
                tableHTML += '        </tr>';
                tableHTML += '    </thead>';
                tableHTML += '    <tbody>';

                var numsArr = new Array();
                var idxArr = new Array();
                for (var i = 0; i < lv1Arr.length; i++) {
                    numsArr.push($(lv1Arr[i]).parents('.lv1').find('input[name="lv2[]"]').length);
                    idxArr[i] = 0;
                }

                var len = 1;
                var rowsArr = new Array();
                for (var i = 0; i < numsArr.length; i++) {
                    len = len * numsArr[i];

                    var tmpnum = 1;
                    for (var j = numsArr.length - 1; j > i; j--) {
                        tmpnum = tmpnum * numsArr[j];
                    }
                    rowsArr.push(tmpnum);
                }

                for (var i = 0; i < len; i++) {
                    tableHTML += '        <tr data-row="' + (i+1) + '">';

                    var name = '';
                    for (var j = 0; j < lv1Arr.length; j++) {
                        var n = parseInt(i / rowsArr[j]);
                        if (j == 0) {
                        } else if (j == lv1Arr.length - 1) {
                            n = idxArr[j];
                            if (idxArr[j] + 1 >= numsArr[j]) {
                                idxArr[j] = 0;
                            } else {
                                idxArr[j]++;
                            }
                        } else {
                            var m = parseInt(i / rowsArr[j]);
                            n = m % numsArr[j];
                        }

                        var text = $(lv1Arr[j]).parents('.lv1').find('input[name="lv2[]"]').eq(n).val();
                        if (j != lv1Arr.length - 1) {
                            name += text + '_';
                        } else {
                            name += text;
                        }

                        if (i % rowsArr[j] == 0) {
                            tableHTML += '<td width="50" rowspan="' + rowsArr[j] + '" data-rc="' + (i+1) + '_' + (j+1) + '">' + text + '</td>';
                        }
                    }

                    tableHTML += '<td width="20"><input type="text" name="' + name + '[size]" /></td>';
                    tableHTML += '<td width="20"><input type="text" name="' + name + '[num]" /></td>';
                    tableHTML += '<td width="20"><input type="button" value="删除" class="del" /></td>';
                    tableHTML += '</tr>';
                }
                tableHTML += '</tbody>';
                tableHTML += '</table>';
                $(document).on('click', '.del', function() {
                    $(this).parent().parent().remove();
                });

                $('#lv_table_con').show();
                $('#lv_table').html(tableHTML);
            });
        });

    </script>
    <!--<div class="form-group">-->
        <!--<label class="control-label col-xs-12 col-sm-2"><?php echo __('Norm'); ?>:</label>-->
        <!--<div class="col-xs-12 col-sm-8">-->
            <!--<input id="c-norm" data-rule="required" class="form-control" name="row[norm]" type="text">-->
        <!--</div>-->
    <!--</div>-->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><?php echo __('Content'); ?>:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-content" data-rule="required" class="form-control editor" rows="5" name="row[content]" cols="50"></textarea>
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled"><?php echo __('OK'); ?></button>
            <button type="reset" class="btn btn-default btn-embossed"><?php echo __('Reset'); ?></button>
        </div>
    </div>
</form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src="/assets/js/require<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js" data-main="/assets/js/require-backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js?v=<?php echo $site['version']; ?>"></script>
    </body>
</html>